package cn.iocoder.yudao.module.member.controller.admin.usercidbind;

import cn.iocoder.yudao.module.member.controller.app.usercidbind.vo.AppUserCidBindRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.member.controller.admin.usercidbind.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.usercidbind.UserCidBindDO;
import cn.iocoder.yudao.module.member.convert.usercidbind.UserCidBindConvert;
import cn.iocoder.yudao.module.member.service.usercidbind.UserCidBindService;

@Tag(name = "管理后台 - 推送绑定的id")
@RestController
@RequestMapping("/member/user-cid-bind")
@Validated
public class UserCidBindController {

    @Resource
    private UserCidBindService userCidBindService;

    @PostMapping("/create")
    @Operation(summary = "创建推送绑定的id")
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:create')")
    public CommonResult<Long> createUserCidBind(@Valid @RequestBody UserCidBindCreateReqVO createReqVO) {
        return success(userCidBindService.createUserCidBind(UserCidBindConvert.INSTANCE.convert(createReqVO)));
    }

    @PutMapping("/update")
    @Operation(summary = "更新推送绑定的id")
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:update')")
    public CommonResult<Boolean> updateUserCidBind(@Valid @RequestBody UserCidBindUpdateReqVO updateReqVO) {
        userCidBindService.updateUserCidBind(UserCidBindConvert.INSTANCE.convert(updateReqVO));
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除推送绑定的id")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:delete')")
    public CommonResult<Boolean> deleteUserCidBind(@RequestParam("id") Long id) {
        userCidBindService.deleteUserCidBind(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得推送绑定的id")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:query')")
    public CommonResult<AppUserCidBindRespVO> getUserCidBind(@RequestParam("id") Long id) {
        UserCidBindDO userCidBind = userCidBindService.getUserCidBind(id);
        return success(UserCidBindConvert.INSTANCE.convert(userCidBind));
    }

    @GetMapping("/list")
    @Operation(summary = "获得推送绑定的id列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:query')")
    public CommonResult<List<AppUserCidBindRespVO>> getUserCidBindList(@RequestParam("ids") Collection<Long> ids) {
        List<UserCidBindDO> list = userCidBindService.getUserCidBindList(ids);
        return success(UserCidBindConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得推送绑定的id分页")
    @PreAuthorize("@ss.hasPermission('member:user-cid-bind:query')")
    public CommonResult<PageResult<AppUserCidBindRespVO>> getUserCidBindPage(@Valid UserCidBindPageReqVO pageVO) {
        PageResult<UserCidBindDO> pageResult = userCidBindService.getUserCidBindPage(UserCidBindConvert.INSTANCE.convert(pageVO));
        return success(UserCidBindConvert.INSTANCE.convertPage(pageResult));
    }



}
